package com.lizhi.menu.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.AttentionDto;
import com.lizhi.menu.Dto.IdListDto;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.Attention;
import com.lizhi.menu.service.IAttentionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 关注信息中间Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/system/attention")
@RequiredArgsConstructor
@Api(tags = "关注信息中间管理")
public class AttentionController {
    private final IAttentionService attentionService;

    /**
     * 查询关注信息中间列表
     */
    @GetMapping("/list")
    @ApiOperation("查询关注信息中间列表")
    public Result<Page<Attention>> list(AttentionDto dto) {
        return Result.ok(attentionService.list(dto));
    }

    /**
     * 查询关注信息中间列表
     */
    @GetMapping("/my")
    @ApiOperation("查询我的关注信息中间列表")
    public Result<Page<Attention>> my(AttentionDto dto) {
        dto.setUserId(Long.parseLong(StpUtil.getLoginId().toString()));
        return Result.ok(attentionService.list(dto));
    }

    /**
     * 新增关注信息中间
     */
    @PostMapping
    @ApiOperation("新增关注信息中间")
    public Result<Void> add(@RequestBody Attention attention) {
        attention.setUserId(StpUtil.getLoginId().toString());
        attentionService.add(attention);
        return Result.ok();
    }

    /**
     * 修改关注信息中间
     */
    @PutMapping
    @ApiOperation("修改关注信息中间")
    public Result<Void> edit(@RequestBody Attention attention) {
        attentionService.edit(attention);
        return Result.ok();
    }

    /**
     * 删除关注信息中间
     */
    @DeleteMapping("/remove")
    @ApiOperation("删除关注信息中间")
    public Result<Void> remove(@RequestBody IdListDto dto) {
        attentionService.remove(dto.getIdList());
        return Result.ok();
    }

    /**
     * 删除关注信息中间
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除关注信息中间")
    public Result<Void> remove(@PathVariable String userId) {
        attentionService.remove(userId);
        return Result.ok();
    }
}
